<!--# include virtual="/admin/common/html/header.html"-->
<body>
<div class="page-container">
	<form  class="form form-horizontal" id="form-guidance">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>专业名称</label>
			<div class="formControls skin-minimal col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="材料名称"   id="materialName" name="materialName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>专业编码</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="规格型号"   id="specificcations" name="specificcations">
			</div>
		</div>
		
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>分部名称</label>
			<div class="formControls skin-minimal col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="材料名称"   id="materialName" name="materialName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>分部编码</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="规格型号"   id="specificcations" name="specificcations">
			</div>
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>分项名称</label>
			<div class="formControls skin-minimal col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="材料名称"   id="materialName" name="materialName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>分项编码</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="规格型号"   id="specificcations" name="specificcations">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>文明措施费</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="规格型号"   id="specificcations" name="specificcations">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>规费</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="规格型号"   id="specificcations" name="specificcations">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>单位</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value=""   placeholder="单位"   id="units" name="units">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				工程量：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="含税最高价" id="taxPrice" name="taxPrice">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red"></span>综合单价：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="含税最低价" id="noTaxPrice" name="noTaxPrice">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				综合合价：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="除税最高价" id="maxPrice" name="maxPrice">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red"></span>备注：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<textarea name="remarks" id="remarks" cols="" rows="" class="textarea"  placeholder="备注" onKeyUp="$.Huitextarealength(this,300)"></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/300</p>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button  class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i>保存并提交</button>
				<button class="btn btn-default radius" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>
<!--# include virtual="/admin/common/html/_footer.html"-->
<script>
//var categoryObj={};
//var categoryNameObj={};
//
//$.post('/guidance_service/front/data/category/search.do',{guidanceId:""},function(obj){
////	categoryObj = obj.data;
//	$.each(obj.data,function(i,field){
//		categoryObj[this.categoryCode]=this.categoryName;
//		categoryNameObj[this.categoryName]=this.categoryCode;
//	});
//});
//
//var catalogObj={};
//var guidanceId = GetQueryString('guidanceId');
//$.post('/guidance_service/front/data/catalog/getCatalog.do',{:guidanceId},function(obj){
//	$.each(obj.data.data,function(i,field){
//		catalogObj[this.catalogId]=this.catalogName;
//	});
//});

$(function(){
//	var  infoId= GetQueryString("infoId");
//	var  guidanceId= GetQueryString("guidanceId");
//	if((!guidanceId)||(!infoId))return false;
//	$.post("/guidance_service/front/data/info/get.do",{"infoId":infoId},function(result){
//		if(result.resultCode == 200){
//			$("input[name='materialName']").val(result.data.materialName);
//			$("input[name='specificcations']").val(result.data.specificcations);
//			$("input[name='units']").val(result.data.units);
//			$("input[name='taxPrice']").val(result.data.taxPrice);
//			$("input[name='noTaxPrice']").val(result.data.noTaxPrice);
//			$("input[name='maxPrice']").val(result.data.maxPrice);
//			$("input[name='minPrice']").val(result.data.minPrice);
//			$("input[name='categoryCode']").val(result.data.categoryCode);
//			$("#categoryName").val(categoryObj[result.data.categoryCode]);
//			$("textarea[name='remarks']").val(result.data.remarks);
//			$("input[name='catalogId']").val(result.data.catalogId);
//			$("#catalogName").html(catalogObj[result.data.catalogId]);
//	 	}else{
// 			layer.msg("页面请求出错,系统将自动刷新，请稍后再试！",{icon:2,time:2000},function(){
////	 	    	window.history.back();
// 			});
//	 	}
//	});
});	
$(function(){		
	$("#form-guidance").validate({		//表单验证
		rules:{
			materialName:{required:true,},
			specificcations:{required:true,},
			units:{required:true,},
			catalogId:{required:true,},
			taxPrice:{required:
				{depends:function(){
					if($("#noTaxPrice").val()){
						return false;
					}else if($("#maxPrice").val()){
						return false;
					}else if($("#minPrice").val()){
						return false;
					}else{
						return true;
					}
				}}
			},
			noTaxPrice:{required:
				{depends:function(){
				if($("#taxPrice").val()){
					return false;
				}else if($("#maxPrice").val()){
					return false;
				}else if($("#minPrice").val()){
					return false;
				}else{
						return true;
					}
				}
			}},
			maxPrice:{required:
				{depends:function(){
				if($("#taxPrice").val()){
					return false;
				}else if($("#noTaxPrice").val()){
					return false;
				}else if($("#minPrice").val()){
					return false;
				}else{
						return true;
					}
			}}
			},
			minPrice:{required:
				{depends:function(){
				if($("#taxPrice").val()){
					return false;
				}else if($("#noTaxPrice").val()){
					return false;
				}else if($("#maxPrice").val()){
					return false;
				}else{
						return true;
					}
			}
			}}
		}, 
        messages:{ //提示报错  
            taxPrice:"含税价、除税价、最高价、最低价至少填写一个",  
            noTaxPrice:"含税价、除税价、最高价、最低价至少填写一个"  ,
            maxPrice:"含税价、除税价、最高价、最低价至少填写一个",  
            minPrice:"含税价、除税价、最高价、最低价至少填写一个"  
        },
		debug:true,
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var data =$(form).serialize();
			data +="&infoId="+GetQueryString("infoId");
			data +="&guidanceId="+GetQueryString("guidanceId");
//          data +="&year="+$("input[name='yearMonth']").val().split("-")[0];
//          data +="&month="+$("input[name='yearMonth']").val().split("-")[1]+"月";
//          var areaCode;
//          if($("#province").val()){
//          	areaCode=$("#province").val();
//          }else if($("#city").val()){
//          	areaCode=$("#city").val();
//          }else{
//          	areaCode=$("#province").val();
//          }
//          data+="&areaCode="+areaCode;
            var action= GetQueryString("infoId")?"/guidance_service/front/guidance/info/update.do":"/guidance_service/front/guidance/info/add.do";
			$.post(action,data,function(result){
		 		if(result.resultCode ==200){
		 			layer.msg(result.message,{icon:1,time:2000},function(){
		 				parent.location.reload();
		 				parent.layer.close(parent.layer.getFrameIndex(window.name));
		 				//window.location.href="/admin/modules/guidance/info/infoList.html?guidanceId="+result.data.guidanceId;
		 			});
		 		}else{
		 			layer.msg(result.message,{icon:2,time:2000});
		 		}
			});
		}
	});	
	$("#categoryCode").keyup(function(){
		var categoryCode=$("#categoryCode").val();
		var categoryName=categoryObj[categoryCode];
		$("#categoryName").val(categoryName);
	});
	$("#categoryName").keyup(function(){
		var categoryName=$("#categoryName").val();
		var categoryCode=categoryNameObj[categoryName];
		$("#categoryCode").val(categoryCode);
	});
	$("#catalogName").click(function(){
		var  guidanceId= GetQueryString("guidanceId");
		var  infoId= GetQueryString("infoId");
		var  newInfo= GetQueryString("newInfo");
		var index = layer.open({
			type: 2,
			title: "编辑目录",
			area:["600px","400px"],
			content: "/admin/modules/guidance/info/tree.html?guidanceId="+guidanceId+"&infoId="+infoId+"&newInfo="+newInfo
		});
	});
});
function upCatalog(catalogId,infoId){
	$("#catalogName").html(catalogObj[catalogId]);
	$("#catalogId").val(catalogId);
	console.log(catalogObj);
	console.log(catalogObj[catalogId]);
	if(infoId=="null"||infoId==null||infoId==undefined||infoId=="undefined"||infoId==""){
		return;
	}
	var  oldInfoId= GetQueryString("infoId");
	if(oldInfoId==infoId){
		return;
	}
	var data={"catalogId":catalogId,
			  "infoId":infoId
		};
	$.post("/guidance_service/front/guidance/info/update.do",data,function(rlt){
		if(rlt.resultCode==200){
			layer.msg(rlt.message,{icon:1,time:2000},function(){
				
			});
		}else{
			layer.msg(rlt.message,{icon:2,time:2000});
		}
	});
}

</script>
</body>
</html>
